<template>
  <div class="answers-details">

    <div class="wrapper w">
      <el-breadcrumb :separator-icon='CaretRight'>
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item to="/answers">问答</el-breadcrumb-item>
        <el-breadcrumb-item>问答详情</el-breadcrumb-item>
      </el-breadcrumb>
      <main>
        <div class="answers-details__main">
          <Article v-if="answers" type="problem" :item="answers!" />
          <div class="comment-list">
            <div class="comment-list__header">
              <span class="comment-list__header__title">2个回答</span>
              <div class="comment-list__header__icons">
                <label class="counts">
                  <input type="radio" checked name="comment">
                  <span>得票数</span>
                </label>
                <label class="news">
                  <input type="radio" name="comment">
                  <span>最新</span>
                </label>
              </div>
            </div>
            <Comment v-for="item in comments" :comment="item" :key="item.id" />
          </div>
          <LoginState />
          <div class="similar ">
            <div class="similar__header flex-ac">
              <span class="similar__header__title">相似问题</span>
            </div>
            <Problem v-for="_ in 8" />
            <div class="similar__footer">
              <span>找不到问题？</span>
              <span class="wran">创建新问题</span>
            </div>
          </div>
        </div>
        <div class="answers-details__aside">
          <Card :isIcon="false" title="宣传栏">
            <div class="publicize">
              <div class="publicize__item" v-for="_ in 3">
                <div class="publicize__item__title">前端性能优化设计12问</div>
                <div class="publicize__item__desc">前端性能优化,面试的必问题目</div>
              </div>
            </div>
          </Card>
        </div>
      </main>
    </div>
  </div>
</template>

<script setup lang="ts">
import { CaretRight } from '@element-plus/icons-vue';
import Comment from '@/components/comment/index.vue';
import Article from './Article.vue';
import LoginState from './Login-State.vue';
import Problem from './Problem.vue';
import Card from '@/view/Answers/Card.vue';
import { useRoute } from 'vue-router';
import { onBeforeMount, ref } from 'vue';
import { AnswerDetailsApi } from '@/api/articleApi';
import { IArcticleDetails } from '@/interface/IArticle';
import { IComment } from '@/interface/IComment';

const route = useRoute();
const answers = ref<IArcticleDetails>()

const comments = ref<IComment[]>();

onBeforeMount(() => {
  // 问答详情
  AnswerDetailsApi(route.params.id as string).then(res => {
    answers.value = res.data;
  })
  comments.value = [
    {
      id: "123",
      pid: "0",
      user: {
        id: "12",
        username: "username",
        nickname: "nickName",
        avatar: "图片"
      },
      isCai: false,
      isLive: true,
      liveCount: 20,
      content: "评论内容评论内容评论内容评论内容",
      createTime: "三天前",
      children: [
        {
          id: "1231",
          pid: "123",
          user: {
            id: "12",
            username: "username",
            nickname: "nickNamechi",
            avatar: "图片"
          },
          isCai: false,
          isLive: true,
          liveCount: 20,
          content: "评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容",
          createTime: "三天前",
        }, {
          id: "1231",
          pid: "123",
          user: {
            id: "12",
            username: "username",
            nickname: "nickNamechi",
            avatar: "图片"
          },
          isCai: false,
          isLive: false,
          liveCount: 20,
          content: "评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容",
          createTime: "三天前",
        }, {
          id: "1231",
          pid: "123",
          user: {
            id: "12",
            username: "username",
            nickname: "nickNamechi",
            avatar: "图片"
          },
          isCai: false,
          isLive: true,
          liveCount: 20,
          content: "评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容",
          createTime: "三天前",
        },
        {
          id: "1231",
          pid: "123",
          user: {
            id: "12",
            username: "username",
            nickname: "nickNamechi",
            avatar: "图片"
          },
          isCai: false,
          isLive: true,
          liveCount: 20,
          content: "评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容",
          createTime: "三天前",
        }
      ]
    },
    {
      id: "1231",
      pid: "0",
      user: {
        id: "123",
        username: "username",
        nickname: "nickName",
        avatar: "图片"
      },
      isCai: false,
      isLive: false,
      liveCount: 0,
      content: "评论内容",
      createTime: "三天前",
      children: [
        {
          id: "1231",
          pid: "123",
          user: {
            id: "12",
            username: "username",
            nickname: "nickNamechi",
            avatar: "图片"
          },
          isLive: false,
          isCai: false,
          liveCount: 0,
          content: "评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容",
          createTime: "三天前",
        }, {
          id: "1231",
          pid: "123",
          user: {
            id: "12",
            username: "username",
            nickname: "nickNamechi",
            avatar: "图片"
          },
          isLive: false,
          isCai: false,
          liveCount: 0,
          content: "评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容",
          createTime: "三天前",
        }, {
          id: "1231",
          pid: "123",
          user: {
            id: "12",
            username: "username",
            nickname: "nickNamechi",
            avatar: "图片"
          },
          isLive: false,
          isCai: false,
          liveCount: 20,
          content: "评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容评论内容",
          createTime: "三天前",
        }
      ]
    }
  ]
})


</script>

<style lang="scss" scoped>
.answers-details {
  background-color: #e9ecef;

  .wrapper {
    display: grid;
    grid-template-rows: 40px 1fr;

    >main {
      display: grid;
      grid-template-columns: 1fr 300px;
      gap: 20px;
    }
  }

  &__main {
    display: flex;
    flex-direction: column;
    gap: 20px;

    .comment-list {
      display: grid;
      grid-template-rows: 60px 1fr;
      background-color: #fff;
      border-radius: 2px;

      &__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0px 20px;
        border-bottom: 1px solid #efefef;

        &__title {
          font-size: 18px;
        }

        &__icons {
          display: flex;
          align-items: center;

          input[type="radio"] {
            width: 0;
            height: 0;
            appearance: none;
          }

          label {
            background-color: #fff;
            border: 1px solid #eee;
            padding: 6px 10px;
            min-width: 70px;
            text-align: center;
            color: $color;
            font-size: 14px;

            &:has(input[type="radio"]:checked) {
              background-color: $color;
              color: #fff;
            }
          }
        }
      }
    }



    .similar {
      background-color: red;
      display: grid;
      grid-template-rows: 60px 1fr;
      background-color: #fff;
      border-radius: 2px;
      padding-bottom: 30px;
      margin-bottom: 20px;

      &__header {
        border-bottom: 1px solid #efefef;
        padding: 0 20px;

        &__title {
          font-size: 18px;
        }
      }

      &__footer {
        display: flex;
        align-items: center;
        justify-content: center;
        padding-top: 20px;

        .wran {
          color: $color;

          &:hover {
            text-decoration: underline;
          }
        }
      }
    }
  }

  &__aside {
    .publicize {
      display: grid;
      grid-template-columns: 1fr;
      padding: 0 10px 10px;

      &__item {
        padding: 6px 10px;

        &__title {
          font-weight: bold;
          color: #00965E;
          margin: 4px 0;
        }

        &__desc {
          font-size: 14px;
          color: #727B82;
        }
      }
    }
  }

  :deep(.el-breadcrumb) {
    display: flex;
    align-items: center;
    font-size: 16px;
  }
}

.drop {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #10e0b6;
}
</style>